package itsm.isperp.module.controller.wechat;

import javax.servlet.http.HttpServletRequest;

import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.module.entity.wechat.WechatNewsArticle;
import itsm.isperp.module.service.wechat.WechatNewsArticleService;

import me.chanjar.weixin.common.util.StringUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 控制器
 * 
 * @author lizx
 * @date 2014-11-06 00:11
 */
@Controller
@RequestMapping("wechat/newsArticle")
public class WechatNewsArticleController extends
		BaseController<WechatNewsArticle> {

	@Autowired
	protected WechatNewsArticleService wechatNewsArticleService;

	@Override
	public WechatNewsArticleService getService() {
		return this.wechatNewsArticleService;
	}

	@Override
	public String getPageTitle() {
		return "图文消息";
	}

	@RequestMapping("edit")
	public ModelAndView edit(String id, HttpServletRequest req)
			throws Exception {
		ModelAndView mv = super.edit(id, req);

		WechatNewsArticle model = (WechatNewsArticle) mv.getModel()
				.get("model");
		String nId = req.getParameter("newsId");
		if (StringUtils.isNotEmpty(nId)) {
			model.setNewsId(nId);
		}

		mv.addObject("types", new String[] { "文章", "超链接" });

		return mv;
	}
}
